﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-2 control-label ">场景<font class="red"> *</font></label>
            <div class="col-sm-4" id="scene" col="scene">
            </div>
            <label class="col-sm-2 control-label ">人满自动建群<font class="red"> *</font></label>
            <div class="col-sm-4" id="auto_create_room" col="auto_create_room">
            </div>
        </div>
        <div class="form-group" style="display:none">
            <label class="col-sm-2 control-label ">起始序号<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input type="hidden" id="chat_id" col="chat_id">
                <input type="hidden" id="config_id" col="config_id">
                <input id="room_base_id" col="room_base_id" type="number" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">群名<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="room_base_name" col="room_base_name" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">备注<font class="red"> *</font></label>
            <div class="col-sm-10">
                <input id="remark" col="remark" type="text" class="form-control" />
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    var chatid = ys.request("chatid");
    $(function () {

        $("#scene").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(scene_status_enum).EnumToDictionaryString())) });

        $("#auto_create_room").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(auto_create_room_enum).EnumToDictionaryString())) });

        //$("#auto_create_room>.radio-box").click(function () {
        //    alert("");
        //});

        getForm();

        $('#form').validate({
            rules: {
                scene: { required: true }
            }
        });
    });

    function getForm() {
        if (!ys.isNullOrEmpty(chatid)) {
            ys.ajax({
                url: '@Url.Content("~/QixingManage/GroupChatJoinWay/GetChatFormJson")' + '?chatid=' + chatid,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        id = obj.Data.Id;
                        $('#form').setWebControls(obj.Data);
                    }
                    else
                    {
                        var defaultData = {};
                        defaultData.chat_id = chatid;
                        defaultData.scene = "@scene_status_enum.二维码插件.ParseToInt()";
                        defaultData.auto_create_room = "@auto_create_room_enum.否.ParseToInt()";
                        $('#form').setWebControls(defaultData);
                    }
                }
            });
        }
        else {
            var defaultData = {};
            defaultData.chat_id = chatid;
            defaultData.scene = "@scene_status_enum.二维码插件.ParseToInt()";
            defaultData.auto_create_room = "@auto_create_room_enum.否.ParseToInt()";
            $('#form').setWebControls(defaultData);
        }
    }

    @*function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/QixingManage/GroupChatJoinWay/GetFormJson")' + '?id=' + id,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        $('#form').setWebControls(obj.Data);
                    }
                }
            });
        }
        else {
            var defaultData = {};
            defaultData.scene = "@scene_status_enum.二维码插件.ParseToInt()";
            defaultData.auto_create_room = "@auto_create_room_enum.否.ParseToInt()";
            $('#form').setWebControls(defaultData);
        }
    }*@

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            ys.ajax({
                url: '@Url.Content("~/QixingManage/GroupChatJoinWay/SaveFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>

